<?php

function system_error($message = 'default sysytem error.')
{
	$html = <<<heredoc
	<div id="system_error">
		<span>{$message}</span>
	</div>
heredoc;
	exit($html);
}

function php_error($level, $message, $file, $line)
{
	$error = array(
		E_ERROR           => 'Error',
		E_WARNING         => 'Warning',
		E_PARSE           => 'Parsing Error',
		E_NOTICE          => 'Notice',
		E_CORE_ERROR      => 'Core Error',
		E_CORE_WARNING    => 'Core Warning',
		E_COMPILE_ERROR   => 'Complie Error',
		E_COMPILE_WARNING => 'Complie Warning',
		E_USER_ERROR      => 'Fatal Error',
		E_USER_WARNING    => 'Warning',
		E_USER_NOTICE     => 'Notice',
		E_STRICT          => 'Strict Notice',
		E_RECOVERABLE_ERROR  => 'Recoverable Error'
	);
	exit("<b>{$error[$level]}</b>: {$message} in <b>{$file}</b> on <b>{$line}</b></br>");
}

function base_url()
{
	
}

function site_url()
{
	
}


function load_core($class)
{
	if ( ! file_exists(SYSTEM_DIR . 'classes' . DS . $class . EXT)) system_error();
	include SYSTEM_DIR . 'classes' . DS . $class . EXT;
	$ext_class = strtolower(EXTENSION_PREFIX) . $class . EXT;
	if (file_exists(EXTENSION_DIR . 'classes' . DS . $ext_class))
	{
		include EXTENSION_DIR . 'classes' . DS . $ext_class;
	}
}

function url_route()
{
	$controller = $method = $params = NULL;
	if (isset($_SERVER['PATH_INFO'])) 
	{
		$path = array_slice(explode('/', $_SERVER['PATH_INFO']), 1);
		if (isset($path[0])) $controller = $path[0];
		if (isset($path[1])) $method = $path[1];
		if (isset($path[2])) $params = array_slice($path, 2);
		return array($controller, $method, $params);
	}
	else 
	{
		$path = $_SERVER['REQUEST_URI'];
	}
	return array($controller, $method, $params);
}